package com.jichaoyun.service.impl;

import org.springframework.data.redis.core.RedisTemplate;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jichaoyun.common.model.PagedResult;
import com.jichaoyun.dao.mapper.*;
import com.jichaoyun.model.entity.Realdata;
import com.jichaoyun.model.entity.RealdataCache;
import com.jichaoyun.model.entity.StationInfo;
import com.jichaoyun.model.entity.User;
import com.jichaoyun.common.enums.MyExceptiontType;
import com.jichaoyun.common.ex.MyException;
import com.jichaoyun.service.IRealdataCacheService;
//import com.jichaoyun.model.entity.RealdataCacheMapper;
import com.jichaoyun.service.IStationInfoService;
//import com.jichaoyun.util.TcpUtils.TcpConnect;
import com.jichaoyun.service.util.TcpUtils.TcpConnect;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;

/**
* @author zhen
* @description 针对表【realData_cache】的数据库操作Service实现
* @createDate 2023-12-20 15:25:03
*/
@Service
public class RealdataCacheServiceImpl extends ServiceImpl<RealdataCacheMapper, RealdataCache>
    implements IRealdataCacheService {
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Resource
    private StationInfoMapper stationInfoMapper;

    @Resource
    private StationInfoWaterMapper stationInfoWaterMapper;

    @Resource
    private IStationInfoService stationInfoService;

    @Resource
    private UserMapper userMapper;
    @Autowired
    private RealdataCacheMapper realdataCacheMapper;
    @Resource
    private RealdataMapper realdataMapper;
    private RestTemplate restTemplate;

    @Override
    public RealdataCache getStationSingleInfoById(Integer station_no) {

        return this.baseMapper.getStationSingleInfoById(station_no);
    }
    @Override
    public RealdataCache getWaterStationSingleInfoById(Integer station_no) {

        return this.baseMapper.getWaterStationSingleInfoById(station_no);
    }

    /**
     * 获取该站点的实时流量,压力，温度，频率
     * @param station_no
     * @return
     */
    @Override
    public List<Map<String, Object>> getRealDataById(Integer station_no) {
        return this.baseMapper.getRealDatabyId(station_no);
    }
    /**
     * 查询蒸汽和水的所有总量最近30分钟数据
     * @return
     */
    @Override
    public Map<String, List> getHalfHourTotalRealData() {

        //获取当前时间 和 30分钟前的时间 并 格式化
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime end = LocalDateTime.now().withNano(0);
        LocalDateTime start = end.minusMinutes(30);

        //只取最近的30条
        List<Float> steamList = new ArrayList<>();
        List<Float> waterList = new ArrayList<>();
        List<String> timeList = new ArrayList<>();

        //查找所有蒸汽和水的总站点
        Map<String, List> result = new HashMap<>();
        LambdaQueryWrapper<StationInfo> wrapper1 = new LambdaQueryWrapper<>();
        wrapper1.eq(StationInfo::getUserType,0);
        List<StationInfo> steamStationInfos = stationInfoMapper.selectList(wrapper1);

        LambdaQueryWrapper<StationInfo> wrapper2 = new LambdaQueryWrapper<>();
        wrapper2.eq(StationInfo::getUserType,0);
        List<StationInfo> waterStationInfos = stationInfoWaterMapper.selectList(wrapper2);


        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm");
        for(int i=0;i<30;i++){
            float totalSteam = 0f;
            float totalWater = 0f;
            for (StationInfo steamStationInfo : steamStationInfos) {
                LambdaQueryWrapper<RealdataCache> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.ge(RealdataCache::getRecordTime,start)
                        .lt(RealdataCache::getRecordTime,start.plusSeconds(90))
                        .eq(RealdataCache::getStation,steamStationInfo.getStationNo())
                        .orderByAsc(RealdataCache::getRecordTime);
                List<RealdataCache> list = realdataCacheMapper.selectList(queryWrapper);
                if(list!=null && list.size()!=0){
                    RealdataCache item = list.get(0);
                    totalSteam+=item.getFlow();
                }else {
                    totalSteam+=0f;
                }
            }
            for (StationInfo waterStationInfo : waterStationInfos) {
                List<RealdataCache> list = realdataCacheMapper.waterSelectList(waterStationInfo.getStationNo(),start,start.plusSeconds(90));
                if(list!=null && list.size()!=0){
                    RealdataCache item = list.get(0);
                    totalWater+=item.getFlow();
                }else {
                    totalWater+=0f;
                }
            }
            steamList.add(totalSteam);
            waterList.add(totalWater);
            timeList.add(start.format(dateTimeFormatter));
            start = start.plusSeconds(60);
        }
        result.put("近30分钟总蒸汽流速", steamList);
        result.put("近30分钟总回水流速", waterList);
        result.put("时间段", timeList);

        return result;
    }
    /**
     * 实时流量top5
     * @return
     */
    @Override
    public List<RealdataCache> getTop5Flow(Integer userId) {
        User user = this.userMapper.selectById(userId);
        List<RealdataCache> datalist;

        if (user.getUserRole() == 0){
            datalist =  this.baseMapper.selectTop5FlowSelf(userId);
        }else {
            datalist =  this.baseMapper.selectTop5Flow();
        }

        //加上名称字段
        return getRealdataCache(datalist);
    }

    /**
     * 实时温度top5
     * @return
     */
    @Override
    public List<RealdataCache> getTop5Temp(Integer userId) {
        User user = this.userMapper.selectById(userId);
        List<RealdataCache> datalist;

        if (user.getUserRole() == 0){
            datalist =  this.baseMapper.selectTop5TempSelf(userId);
        }else {
            datalist =  this.baseMapper.selectTop5Temp();
        }
        return getRealdataCache(datalist);
    }

    /**
     * 实时压力top5
     * @return
     */
    @Override
    public List<RealdataCache> getTop5Pres(Integer userId) {
        User user = this.userMapper.selectById(userId);
        List<RealdataCache> datalist;

        if (user.getUserRole() == 0){
            datalist =  this.baseMapper.selectTop5PresSelf(userId);
        }else {
            datalist =  this.baseMapper.selectTop5Pres();
        }
        return getRealdataCache(datalist);
    }

    /**
     * 查询多用户实时信息
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    public PagedResult getMultiRealInfovo(Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<RealdataCache> multiRealInfoList = this.baseMapper.getMultiRealInfo();

        for (int i=0;i<multiRealInfoList.size();i++) {
            RealdataCache multiRealInfo = multiRealInfoList.get(i);
            Integer station = multiRealInfo.getStation();
            LambdaQueryWrapper<StationInfo> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(StationInfo::getStationNo,station);
            StationInfo staObject = stationInfoMapper.selectOne(wrapper);
            if(staObject == null){
                throw new MyException(MyExceptiontType.Other,null);
//                multiRealInfo.setStationName("未知站点错误");
            }else {
                multiRealInfo.setStationName(staObject.getStationName());
            }
        }
        PageInfo<RealdataCache> pagelist = new PageInfo<>(multiRealInfoList);
        PagedResult result = new PagedResult();
        result.setTotal((int) pagelist.getTotal());
        result.setPages(pagelist.getPages());
        result.setRows(pagelist.getList());
        return result;
    }

    /**
     * 查询近30分钟数据
     * @param stationName
     * @return
     */
    @Override
    public Map<String, List<Object>> getHalfHourRealData(String stationName) {

        //获取当前时间 和 30分钟前的时间 并 格式化
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime end = LocalDateTime.now().withNano(0);
        LocalDateTime start = end.minusMinutes(30);

        //根据传入的站点名称找到站点id
        Map<String, List<Object>> result = new HashMap<>();
        LambdaQueryWrapper<StationInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StationInfo::getStationName,stationName.trim());
        Integer stationId = stationInfoService.getOne(wrapper).getStationNo();

        //只取最近的30条
        List<Float> flowList = new ArrayList<>();
        List<Float> tempList = new ArrayList<>();
        List<Float> presList = new ArrayList<>();
        List<Float> freqList = new ArrayList<>();
        List<String> timeList = new ArrayList<>();

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm");
        for(int i=0;i<30;i++){
            LambdaQueryWrapper<RealdataCache> queryWrapper = new LambdaQueryWrapper<>();
//            System.out.println(start);
//            System.out.println(start.plusSeconds(90));
            queryWrapper.ge(RealdataCache::getRecordTime,start)
                    .lt(RealdataCache::getRecordTime,start.plusSeconds(90))
                    .eq(RealdataCache::getStation,stationId)
                    .orderByAsc(RealdataCache::getRecordTime);
            List<RealdataCache> list = this.baseMapper.selectList(queryWrapper);
            if(list!=null && list.size()!=0){
                RealdataCache item = list.get(0);
                LocalDateTime time = item.getRecordTime();
                flowList.add(item.getFlow());
                tempList.add(item.getTemp());
                presList.add(item.getPres());
                freqList.add(item.getFreq());
                timeList.add(time.format(dateTimeFormatter));
            }else {
                flowList.add(0f);
                tempList.add(0f);
                presList.add(0f);
                freqList.add(0f);
                timeList.add(start.format(dateTimeFormatter));
            }
            start = start.plusSeconds(60);
        }
        result.put("近30分钟流量", Collections.singletonList(flowList));
        result.put("近30分钟温度", Collections.singletonList(tempList));
        result.put("近30分钟压力", Collections.singletonList(presList));
        result.put("近30分钟频率", Collections.singletonList(freqList));
        result.put("时间段", Collections.singletonList(timeList));

        return result;
    }

    public String calculateMinuteLossRareByStation(LocalDateTime time, Integer stationNo ,Float mainFlow){
        //查出其子节点表
        LambdaQueryWrapper<StationInfo> wp = new LambdaQueryWrapper<>();
        wp.eq(StationInfo::getFatherStationNo,stationNo);
        List<StationInfo> divStation= stationInfoMapper.selectList(wp);
        if(divStation == null || divStation.size()==0){
            return "0.00";
        }

        //计算分表的流量和
        Float div_f = 0f;
        LocalDateTime start1 = time.withSecond(0);
        LocalDateTime end1= time.withSecond(0).plusSeconds(59);
        for (StationInfo stationInfo : divStation) {
            LambdaQueryWrapper<RealdataCache> wrapper2 = new LambdaQueryWrapper<>();
            wrapper2.le(RealdataCache::getRecordTime,end1).ge(RealdataCache::getRecordTime,start1)
                    .eq(RealdataCache::getStation,stationInfo.getStationNo()).orderByDesc(RealdataCache::getRealId);
            RealdataCache one = this.baseMapper.selectOne(wrapper2);
            if (one == null){
                div_f+=0f;
            }else {
                div_f+=one.getFlow();
            }
        }

        return String.format("%.2f",(mainFlow-div_f)/mainFlow);

    }


    /**
     * 查询24小时曲线
     *
     * @return
     */
//
    @Override
    public Map<String, List> get24HourRealData() {
        //获取当前时间 和 24小时前的时间 并 格式化
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm");
        List<Float> steamList = new ArrayList<>();
        List<Float> subSteamList = new ArrayList<>();
        List<Float> pipeLossList = new ArrayList<>();
        List<String> timeList = new ArrayList<>();
        Map<String, List> result = new HashMap<>();

        //查找所有蒸汽的总(0) 分(1) 站点编号
        List<Integer> steamStationNos = stationInfoMapper.selectStationNoListByUserType(0);
        List<Integer> steamSubStationNos = stationInfoMapper.selectStationNoListByUserType(1);

//        if (redisTemplate.hasKey("24HourRealData")){
//
//            LocalDateTime end = LocalDateTime.now().withNano(0);
//            LocalDateTime start = end.minusMinutes(1);
//            LocalDateTime deleteTime = end.minusMinutes(60 * 24 + 1);
//            String deleteTimeKey = deleteTime.format(formatter);
//            redisTemplate.delete(deleteTimeKey);
//
//            // 获取start的日期:小时:分钟得到一个string类型的
//            String timeKey = start.format(formatter);
//            float totalSteamValue = realdataMapper.getStationFlowSumByStationNoList(steamStationNos,start,end);
//            float totalSubSteamValue = realdataMapper.getStationFlowSumByStationNoList(steamSubStationNos,start,end);
//            ArrayList<Float> totalSteamValueList = new ArrayList<Float>();
//            totalSteamValueList.add(totalSteamValue);
//            totalSteamValueList.add(totalSubSteamValue);
//
//            redisTemplate.opsForValue().set(timeKey, totalSteamValueList);
//        }
//        else {
//            LocalDateTime end = LocalDateTime.now().withNano(0);
//            LocalDateTime start = end.minusMinutes(60 * 24);
//            List<Realdata> steamData = realdataMapper.historySelectAllBetweenTimeRange(steamStationNos, start, end);
//            List<Realdata> steamSubData = realdataMapper.historySelectAllBetweenTimeRange(steamSubStationNos, start, end);
//            for (int i = 0; i < 1440; i++) {
//                float totalSteam = 0f;
//                float totalSubSteam = 0f;
//                LocalDateTime TempStart = start.plusMinutes(i);
//                LocalDateTime TempEnd = start.plusMinutes(i + 1);
//
//                for (Realdata steam : steamData) {
//                    if (steam.getRecordTime().isAfter(TempStart) && steam.getRecordTime().isBefore(TempEnd)) {
//                        totalSteam += steam.getFlow();
//                    }
//                }
//                for (Realdata steam : steamSubData) {
//                    if (steam.getRecordTime().isAfter(TempStart) && steam.getRecordTime().isBefore(TempEnd)) {
//                        totalSubSteam += steam.getFlow();
//                    }
//                }
//                ArrayList<Float> totalSteamValueList = new ArrayList<Float>();
//                String timeKey = TempStart.format(formatter);
//                totalSteamValueList.add(totalSteam);
//                totalSteamValueList.add(totalSubSteam);
//                redisTemplate.opsForValue().set(timeKey, totalSteamValueList);
//            }
//        }


        //获取当前时间 和 24小时前的时间 并 格式化


        LocalDateTime end = LocalDateTime.now().withNano(0);
        LocalDateTime start = end.minusMinutes(60*24);

        // 一次性查询最近24小时的所有总\分表的记录
        List<Realdata> steamData = realdataMapper.historySelectAllBetweenTimeRange(steamStationNos,start,end);
        List<Realdata> steamSubData = realdataMapper.historySelectAllBetweenTimeRange(steamSubStationNos,start,end);

        for(int i=0;i<1440;i++){
            float totalSteam = 0f;
            float totalSubSteam = 0f;

            LocalDateTime TempStart = start.plusMinutes(i);
            LocalDateTime TempEnd = start.plusMinutes(i+1);
            for(Realdata steam : steamData){
                if(steam.getRecordTime().isAfter(TempStart) && steam.getRecordTime().isBefore(TempEnd)){
                    totalSteam += steam.getFlow();
                }
            }
            for(Realdata steam : steamSubData){
                if(steam.getRecordTime().isAfter(TempStart) && steam.getRecordTime().isBefore(TempEnd)){
                    totalSubSteam += steam.getFlow();
                }
            }
            steamList.add(totalSteam);
            pipeLossList.add(totalSubSteam);
            for(int h = 0; h<steamList.size();h++){
                subSteamList.add(steamList.get(h)-pipeLossList.get(h));
            }
            timeList.add(TempStart.format(dateTimeFormatter));
        }
//        for(int i=0;i<1440;i++){
//            float totalSteam = 0f;
//            float totalSubSteam = 0f;
//            // 每分钟查询一次:获得所有总表的总流量
//            float PerMinuteSteamStationFlowSum = realdataMapper.getStationFlowSumByStationNoList(steamStationNos,start,start.plusMinutes(1));
//            totalSteam += PerMinuteSteamStationFlowSum;
//
//            float PerMinuteSteamSubStationFlowSum = realdataMapper.getStationFlowSumByStationNoList(steamSubStationNos,start,start.plusMinutes(1));
//            totalSubSteam += PerMinuteSteamSubStationFlowSum;
//
//            steamList.add(totalSteam);
//            pipeLossList.add(totalSubSteam);//管损=所有蒸汽的总站点的总流量-所有蒸汽的分站点的总流量
//            timeList.add(start.format(dateTimeFormatter));
//            start = start.plusMinutes(1);
//        }

        result.put("近24小时总蒸汽流速", steamList);
        result.put("近24小时分表总蒸汽",subSteamList);
        result.put("近24小时总蒸汽管损", pipeLossList);
        result.put("时间点", timeList);

        return result;

    }

    /**
     * 管损报表查询-查询右边的图
     * 查找最近十分钟的数据
     * @return
     */
    @Override
    public Map<String, Object> getTenMinutesLineLossForm(Integer lineId) {
        LocalDateTime end = LocalDateTime.now();
        LocalDateTime start = end.minusMinutes(10);

        HashMap<String,Object> resMap = new HashMap<>();
        List<String> pipeLossList = new ArrayList<>();
        List<String> pipeLossTimeList = new ArrayList<>();
        LocalDateTime s1 = start;

        long betw = ChronoUnit.MINUTES.between(start,end);
        //这里查出这条线路的总表
        LambdaQueryWrapper<StationInfo> wp = new LambdaQueryWrapper<>();
        wp.eq(StationInfo::getLineId,lineId).eq(StationInfo::getUserType,0);
        List<StationInfo> mains = stationInfoMapper.selectList(wp);

        //给前端最多返回这么多的数据，，这里进行均等分割算法
        List<Realdata> realdataList = new ArrayList<>();

        //说明执行完了，数据量应该不大，全部显示
        while (end.compareTo(start)>0) {
            start = start.plusMinutes(1);
            LocalDateTime e = start.plusSeconds(90);
            float total = 0f;
            Realdata realdata = null;
            for (StationInfo main : mains) {
                realdata= realdataMapper.historySelectOne(main.getStationNo(), start, e);
                if(realdata!=null) {
                    total+=realdata.getFlow();
                } else {
                    total+=0;
                }
            }
            float loss=0;
            if(realdata!=null){
                if(realdata.getSubTotalFlow()==null) realdata.setSubTotalFlow(0f);
                loss = total - realdata.getSubTotalFlow();
            }
            pipeLossList.add(String.format("%.2f",loss));
            pipeLossTimeList.add(String.valueOf(start));
        }

        resMap.put("管损数据序列",pipeLossList);
        resMap.put("管损时间序列",pipeLossTimeList);

        return resMap;
    }



    /**
     * 主要是给realdata的站名赋值
     */
    private List<RealdataCache> getRealdataCache(@NotNull List<RealdataCache> datalist) {
        for (RealdataCache realdata : datalist) {
            Integer station_no = realdata.getStation();
            LambdaQueryWrapper<StationInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            lambdaQueryWrapper.eq(StationInfo::getStationNo,station_no);
            String station_name =  stationInfoMapper.selectOne(lambdaQueryWrapper).getStationName();
            realdata.setStationName(station_name);
        }
        return datalist;
    }


    /**
     * 查询多用户实时信息条件
     *
     * @return
     */
    @Override
    public ArrayList<RealdataCache> getMultiRealInfovoBy(Integer lineId, String identity, String sort) {

        List<RealdataCache> multiRealInfoList = this.baseMapper.getMultiRealInfoBy(lineId,identity,sort);

        HashMap<Integer, RealdataCache> map = new HashMap<>();
        for (int i=0;i<multiRealInfoList.size();i++) {
            map.put(multiRealInfoList.get(i).getStation(),multiRealInfoList.get(i));
        }
        LambdaQueryWrapper<StationInfo> swrapper = new LambdaQueryWrapper<>();
        swrapper.eq(StationInfo::getIsUse,true);
        if( lineId != null &&  lineId!=-1 ) swrapper.eq(StationInfo::getLineId,lineId);
        List<StationInfo> stationInfos = stationInfoMapper.selectList(swrapper);

        for (StationInfo stationInfo : stationInfos) {
            Integer staNo = stationInfo.getStationNo();
            RealdataCache realdataCache = map.get(staNo);
            if(map.containsKey(staNo)){
                if(TcpConnect.isOnLine[staNo]){
                    realdataCache.setComState(true);
                }else {
                    realdataCache.setComState(false);
                }
                realdataCache.setStationName(stationInfo.getStationName());
                realdataCache.setRecordTime(realdataCache.getRecordTime().withNano(0));
            }else{
                RealdataCache realdataCache1 = new RealdataCache();
                realdataCache1.setStationName(stationInfo.getStationName());
                realdataCache1.setStation(staNo);
                realdataCache1.setAddr(stationInfo.getAddr());
                realdataCache1.setComState(false);
                realdataCache1.setRecordTime(LocalDateTime.now().withNano(0));
                multiRealInfoList.add(realdataCache1);
            }
        }
        ArrayList<RealdataCache> reslist = new ArrayList<>();

        for(int i =0;i< multiRealInfoList.size();i++){
            reslist.add(multiRealInfoList.get(i));
        }

        return reslist;
    }
    @Override
    public Map<String, Object> getIndustryData() {
        // 子查询：获取每个站点最新的时间戳
        String subQuery1 = "(SELECT station, MAX(write_time) AS max_write_time FROM realData_cache WHERE station IN (317,319,320) GROUP BY station)";

        // 主查询：根据子查询的结果获取最新的数据
        LambdaQueryWrapper<RealdataCache> queryWrapper1 = new LambdaQueryWrapper<>();
        queryWrapper1.apply("EXISTS (SELECT 1 FROM " + subQuery1 + " t WHERE t.station = realData_cache.station AND t.max_write_time = realData_cache.write_time)");
        queryWrapper1.in(RealdataCache::getStation, 317, 319, 320);
        List<RealdataCache> list1 = realdataCacheMapper.selectList(queryWrapper1);

        Float huagong = 0f;
        for (RealdataCache item : list1) {
            huagong += item.getFlow();
        }

        // 子查询：获取每个站点最新的时间戳
        String subQuery2 = "(SELECT station, MAX(write_time) AS max_write_time FROM realData_cache WHERE station IN (318, 321, 322, 330) GROUP BY station)";

        // 主查询：根据子查询的结果获取最新的数据
        LambdaQueryWrapper<RealdataCache> queryWrapper2 = new LambdaQueryWrapper<>();
        queryWrapper2.apply("EXISTS (SELECT 1 FROM " + subQuery2 + " t WHERE t.station = realData_cache.station AND t.max_write_time = realData_cache.write_time)");
        queryWrapper2.in(RealdataCache::getStation, 318, 321, 322, 330);
        List<RealdataCache> list2 = realdataCacheMapper.selectList(queryWrapper2);

        Float cailiao = 0f;
        for (RealdataCache item : list2) {
            cailiao += item.getFlow();
        }

        // 子查询：获取每个站点最新的时间戳
        String subQuery3 = "(SELECT station, MAX(write_time) AS max_write_time FROM realData_cache WHERE station IN (324) GROUP BY station)";

        // 主查询：根据子查询的结果获取最新的数据
        LambdaQueryWrapper<RealdataCache> queryWrapper3 = new LambdaQueryWrapper<>();
        queryWrapper3.apply("EXISTS (SELECT 1 FROM " + subQuery3 + " t WHERE t.station = realData_cache.station AND t.max_write_time = realData_cache.write_time)");
        queryWrapper3.in(RealdataCache::getStation, 324);
        List<RealdataCache> list3 = realdataCacheMapper.selectList(queryWrapper3);

        Float fangzhi = 0f;
        for (RealdataCache item : list3) {
            fangzhi += item.getFlow();
        }

        Map<String, Object> res = new HashMap<>();
        res.put("cailiao", cailiao);
        res.put("huagong", huagong);
        res.put("fangzhi", fangzhi);
        return res;
    }
}




